package io.renren.modules.worklistinfo.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.emp.entity.EmployeeEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.worklistinfo.entity.WorklistinfoEntity;
import io.renren.modules.worklistinfo.service.WorklistinfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

@RestController
@RequestMapping("worklistinfo/worklistinfo")
public class WorklistinfoController {
    @Autowired
    private WorklistinfoService worklistinfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("worklistinfo:worklistinfo:list")
    public R list(@RequestParam Map<String, Object> params){
       // PageUtils page = worklistinfoService.queryPage(params);
        int pageIndex = Integer.parseInt(String.valueOf(params.get("page")));
        int pageSize = Integer.parseInt(String.valueOf(params.get("limit")));
        String userinput = String.valueOf(params.get("key"));
        Page<WorklistinfoEntity> page = new Page<>(pageIndex,pageSize);

        // 通过调用自定义dao层实现
        worklistinfoService.selectByUserInput(userinput,page);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{workno}")
    @RequiresPermissions("worklistinfo:worklistinfo:info")
    public R info(@PathVariable("workno") Integer workno){
		WorklistinfoEntity worklistinfo = worklistinfoService.getById(workno);

        return R.ok().put("worklistinfo", worklistinfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("worklistinfo:worklistinfo:save")
    public R save(@RequestBody WorklistinfoEntity worklistinfo){
		worklistinfoService.save(worklistinfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("worklistinfo:worklistinfo:update")
    public R update(@RequestBody WorklistinfoEntity worklistinfo){
		worklistinfoService.updateById(worklistinfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("worklistinfo:worklistinfo:delete")
    public R delete(@RequestBody Integer[] worknos){
		worklistinfoService.removeByIds(Arrays.asList(worknos));

        return R.ok();
    }

}
